package com.atguigu.stgy.admin.controller;
import com.atguigu.stgy.admin.service.FacilityInfoService;
import com.atguigu.stgy.model.entity.FacilityInfo;
import com.atguigu.stgy.model.enums.FacilityTypeEnum;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.result.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
* 配套信息表(facility_info)表控制层
*
* @author xxxxx
*/
@RestController
@Tag(name = "配套信息管理模块")
@RequestMapping("admin/facility")
public class FacilityInfoController {
/**
* 服务对象
*/
@Resource
private FacilityInfoService facilityInfoService;

@Operation(summary = "根据类型查询配套信息列表")
@GetMapping("list")
    public R<List<FacilityInfo>> list(@RequestParam(required = false) FacilityTypeEnum type){

  List<FacilityInfo>  facilityInfos=facilityInfoService.listFacilityInfoByType(type);
    return R.ok(facilityInfos);
}



   // http://localhost:8080/admin/facility/deleteById?id=48
@DeleteMapping("deleteById")
@Operation(summary = "删除指定配套信息")
    public R  deleteById(@RequestParam("id") Long id ){
    boolean b = facilityInfoService.removeById(id);
    return b?R.ok():R.fail(ResultCodeEnum.FAIL);
}
 // Post   http://localhost:8080/admin/facility/saveOrUpdate

    @PostMapping("saveOrUpdate")

    @Operation(summary = "新增或更新标签")
    public R  saveOrUpate(@RequestBody FacilityInfo facilityInfo){
        boolean b = facilityInfoService.saveOrUpdate(facilityInfo);
        return b?R.ok():R.fail(ResultCodeEnum.FAIL);
    }
}
